/**
 * Created by caosh on 2018/5/14 0014.
 */
var ModifyPwd = new Vue({
    el: '#modify-pwd',
    data: {
        user: {
            loginName: '',
            oldPwd: '',
            newPwd: ''
        },
        confirmPwd: ''
    },
    methods: {
        editPwd: function () {
            var _this = this;
            if (!_this.checkUser()) {
                return;
            }

            _this.setAjaxOptions('/editPwd', _this.user, function (result, status, jqXHR) {
                if (result.retCode == 0) {
                    console.log('密码修改成功！');
                } else {
                    console.log(result.errMsg);
                }
            });

            _this.doAjax();
        },
        checkUser: function () {
            var valid = true;
            if (this.user.oldPwd.length<6) {
                valid = false;
            }

            if (this.user.oldPwd != this.userinfo.password) {
                valid = false;
            }

            if (this.user.newPwd.length<6) {
                valid = false;
            }

            if (this.confirmPwd != this.user.newPwd) {
                valid = false;
            }

            return valid;
        }
    },
    mixins: [AjaxMixin, StatusMixin, UserMixin],
    mounted: function () {
        Vue.useLayerElement();
        this.user.loginName = this.userinfo.loginName;
        Vue.useLayerForm();
    },
    watch: {
        'user.oldPwd': function (val, oldVal) {
            if (val.length>20) {
                this.user.oldPwd = val.substring(0, 20);
            }
        },
        'user.newPwd': function (val, oldVal) {
            if (val.length>20) {
                this.user.newPwd = val.substring(0, 20);
            }
        },
        'confirmPwd': function (val, oldVal) {
            if (val.length>20) {
                this.confirmPwd = val.substring(0, 20);
            }
        }
    }
});